<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');

$team = Table::FetchForce('team', $_GET['appkey']);
$tatics = explode('|', $team['tatics']);
$currentTatics = '';
$taticsDes = '';
foreach($tatics as $sid=>$one){
	$tatics[$sid] = explode(',', $one);
	$discountTmp = explode('-', $tatics[$sid][2]);
	if($tatics[$sid][0] == 0){
		$taticsDes .= '影响力小于'.$tatics[$sid][1];
	} elseif($tatics[$sid][1] == 0){
		$taticsDes .= '影响力大于'.$tatics[$sid][0];
	} else{
		$taticsDes .= '影响力在'.$tatics[$sid][0].'至'.$tatics[$sid][1].'间';
	}
	if(!$discountTmp[1]){
		$taticsDes .= '，可获得'.$discountTmp[0].'元的代金券<br/>';
	} else{
		$taticsDes .= '，可获得'.$discountTmp[0].'到'.$discountTmp[1].'元代金券<br/>';
	}
	if($user_network_weights['total'] && ($user_network_weights['total'] >= $tatics[$sid][0])){
		if($tatics[$sid][1] == 0){
			$team['discount_rate'] = $tatics[$sid][2];
		} elseif($user_network_weights['total'] < $tatics[$sid][1]){
			if($user_network_weights['total'] == 0){
				$team['discount_rate'] = $discountTmp[1];
			} else{
				// 低折扣+（高折扣-低折扣）/（高影响力-低影响力）*（个人影响力-低影响力）
				$currentTatics .= '您可获得'.(round($discountTmp[0] + (($discountTmp[1] - $discountTmp[0])/($tatics[$sid][1] - $tatics[$sid][0]))*($user_network_weights['total'] - $tatics[$sid][0]), 1)).'元代金券<br/>';
			}
		}
	}
}
if(!$user_network_weights['total']){
	$taticsDes .= '<br/>您当前尚未登录<享省钱>';
} else{
	$taticsDes .= '<br/>'.$currentTatics;
}

include template('connect_share_btn');
